package com.dujiu.leetcode.dp;

public class P509 {
    // 斐波那契数列
    public int fib(int n) {
        if (n == 0 || n == 1){
            return n;
        }
        int dp0 = 1;
        int dp1 = 1;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum = dp0 + dp1;
            dp0 = dp1;
            dp1 = sum;
        }
        return sum;
    }
}
